package a51qindian.com.comprehensive.activity;

import android.Manifest;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;

import com.li.bottom.BottomNavigationItem;
import com.li.bottom.BottomNavigationView;
import com.li.widget.FixedViewPager;
import com.li.widget.TopNavigationBar;

import java.util.ArrayList;
import java.util.List;

import a51qindian.com.comprehensive.Const;
import a51qindian.com.comprehensive.R;
import a51qindian.com.comprehensive.adapter.MainPagerAdapter;
import a51qindian.com.comprehensive.base.QDBaseActivity;
import a51qindian.com.comprehensive.fragment.MineFragment;
import a51qindian.com.comprehensive.fragment.MsgFragment;
import a51qindian.com.comprehensive.fragment.WorkCenterFragment;
import butterknife.BindView;


/**
 * Author: Li
 * Date: 2017/9/11 0011
 * Description: 主界面
 */

public class MainActivity extends QDBaseActivity implements BottomNavigationView.OnTabSelectedListener {


    @BindView(R.id.bottom_navigation)
    BottomNavigationView mBottomNavigation;
    @BindView(R.id.top_navigation)
    TopNavigationBar mTopNavigation;
    @BindView(R.id.pager_main)
    FixedViewPager mPagerMain;

    private static final String MSG = "消息";
    private static final String WORK_CENTER = "工作中心";
    private static final String MINE = "个人中心";

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }


    @Override
    protected void initSth() {
        super.initSth();
        List<Fragment> fragmentList = new ArrayList<>();

        fragmentList.add(new MsgFragment());
        fragmentList.add(WorkCenterFragment.newInstance(getIntent().getStringExtra(Const.USER_TYPE)));
        fragmentList.add(new MineFragment());

        mPagerMain.setOffscreenPageLimit(fragmentList.size());
        MainPagerAdapter pagerAdapter = new MainPagerAdapter(getSupportFragmentManager(), fragmentList);
        mPagerMain.setAdapter(pagerAdapter);


        mBottomNavigation.setOnTabSelectedListener(this);
        getContentView().post(new Runnable() {
            @Override
            public void run() {
                mBottomNavigation.getChildAt(1).performClick();
            }
        });

        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);

    }

    @Override
    public void onSelected(int pos, BottomNavigationItem item) {
        switch (pos) {
            case 0:
                mTopNavigation.setTitle(MSG);
                break;
            case 1:
                mTopNavigation.setTitle(WORK_CENTER);
                break;
            case 2:
                mTopNavigation.setTitle(MINE);
                break;
        }
        mPagerMain.setCurrentItem(pos, false);
    }

    @Override
    public void onUnSelected(int pos, BottomNavigationItem item) {

    }

    @Override
    public void onReSelected(int pos, BottomNavigationItem item) {

    }


}
